home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifRadioButtonMenuItemUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  121 lines

  1. /*
  2.  * @(#)MotifRadioButtonMenuItemUI.java    1.29 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.event.*;
  25. import com.sun.java.swing.plaf.*;
  26. import com.sun.java.swing.plaf.basic.BasicRadioButtonMenuItemUI;
  27. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  28.  
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import java.io.Serializable;
  32.  
  33.  
  34. /**
  35.  * MotifRadioButtonMenuItem implementation
  36.  * <p>
  37.  * Warning: serialized objects of this class will not be compatible with
  38.  * future swing releases.  The current serialization support is appropriate
  39.  * for short term storage or RMI between Swing1.0 applications.  It will
  40.  * not be possible to load serialized Swing1.0 objects with future releases
  41.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  42.  * baseline for the serialized form of Swing objects.
  43.  *
  44.  * @version 1.29 02/02/98
  45.  * @author Georges Saab
  46.  * @author Rich Schiavi
  47.  */
  48. public class MotifRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI
  49. {
  50.     protected ChangeListener changeListener;
  51.  
  52.     public static ComponentUI createUI(JComponent b) {
  53.         return new MotifRadioButtonMenuItemUI();
  54.     }
  55.  
  56.     protected void initListeners(JComponent c) {
  57.     super.initListeners(c);
  58.         changeListener = createChangeListener(c);
  59.     }
  60.     
  61.     protected void addListeners(JComponent c) {
  62.     super.addListeners(c);
  63.         ((JMenuItem)c).addChangeListener(changeListener);    
  64.     }
  65.  
  66.     protected void removeListeners(JComponent c) {
  67.     super.removeListeners(c);
  68.     ((JMenuItem)c).removeChangeListener(changeListener);
  69.     }
  70.  
  71.     protected ChangeListener createChangeListener(JComponent c) {
  72.     return new MenuChangeListener();
  73.     }
  74.  
  75.     protected class MenuChangeListener implements ChangeListener, Serializable {
  76.  
  77.  
  78.     public void stateChanged(ChangeEvent e) {
  79.         JMenuItem c = (JMenuItem)e.getSource();
  80.         if (c.isArmed()) {
  81.         c.setBorderPainted(true);
  82.         } else {
  83.         c.setBorderPainted(false);
  84.         }
  85.     }
  86.     }
  87.  
  88.     public void paint(Graphics g, JComponent c) {
  89.     MotifGraphicsUtils.paintMenuItem(g, c, ((JRadioButtonMenuItem)c).getSelectedIcon(),menuArrow,
  90.                      pressedBackground, pressedForeground,
  91.                      defaultTextIconGap);
  92.     }
  93.  
  94.     public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) {
  95.         Point p = e.getPoint();
  96.         if(p.x >= 0 && p.x < item.getWidth() &&
  97.            p.y >= 0 && p.y < item.getHeight()) {
  98.             if(e.getID() == MouseEvent.MOUSE_RELEASED) {
  99.                 manager.clearSelectedPath();
  100.                 item.doClick(0);
  101.             } else if(e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_PRESSED)
  102.                 manager.setSelectedPath(path);
  103.         } else if(item.getModel().isArmed() && e.getID() == MouseEvent.MOUSE_DRAGGED) {
  104.             MenuElement newPath[] = new MenuElement[path.length-1];
  105.             int i,c;
  106.             for(i=0,c=path.length-1;i<c;i++)
  107.                 newPath[i] = path[i];
  108.             manager.setSelectedPath(newPath);
  109.         }
  110.     }
  111.  
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.